import java.util.HashMap;
import java.util.Map;

class Solution {
    public int minNumberOfFrogs(String croakOfFrogs) {
        Map<Character, Integer> map = new HashMap<>();
        int[] hash = new int[5];
        String t = "croak";
        int n = t.length();
        for (int i = 0; i < t.length(); i++) {
            map.put(t.charAt(i), i);
        }
        for (char c : croakOfFrogs.toCharArray()) {
            if (c == t.charAt(0)) {
                if (hash[n - 1] != 0) {
                    hash[n - 1]--;
                }
                hash[0]++;
            } else {
                int i = map.get(c);
                if (hash[i - 1] == 0) return -1;
                hash[i - 1]--;
                hash[i]++;
            }
        }
        for (int i = 0; i < n - 1; i++) {
            if (hash[i] != 0) {
                return -1;
            }
        }
        return hash[n - 1];
    }

    public static void main(String[] args) {
        Solution solution = new Solution();
        System.out.println(solution.minNumberOfFrogs("croakcroak"));
    }
}